using System;
using UnityEngine;
using UnityEngine.UIElements;

namespace DA.AnimGraph.Editor {

    internal class GenericDropdownButton : VisualElement {

        Button button;
        //Label label;
        GenericDropdownMenu menu;

        public GenericDropdownButton(string text) {
            name = "menu_button";

            button = new Button();
            button.text = text;
            button.clicked += OnClick;

            Add(button);

            menu = new GenericDropdownMenu();
        }

        private void OnClick() {
            var menuPos = button.clickable.lastMousePosition;
            menuPos = button.LocalToWorld(menuPos);
            menu.DropDown(new Rect(menuPos, Vector2.zero), button);
        }

        public void AddMenuItem(params (string, Action)[] items) {
            foreach (var item in items) {
                menu.AddItem(item.Item1, false, item.Item2);
            }
        }

    }
}
